define([],function (){
    return {
        name: 'mu-tree-select',
        template:`<el-tree-select
       v-model = "value"
       check-strictly
       :multiple="multiple"
       :placeholder="placeholder"
      :data="locationOptions"
      style="width: 360px"
    />`,
        emits:['update:modelValue'],
        props:{
            modelValue:{
                type:String,
                default:[]
            },
            options:{
                type:Array,
                default:[]
            },
            valueField:{
                type:String,
                default:'value'
            },
            labelField:{
                type:String,
                default:'label'
            },
            children:{
                type:String,
                default:'children'
            },
            placeholder:{
                type:String,
                default:'请选择'
            },
            multiple:{
                type:Boolean,
                default:false
            }
        },
        data(){
            return {
                value:this.modelValue,
            }
        },
        watch:{
            value:function(val){
                // console.log(val)
                this.$emit('update:modelValue',val)
            }
        },
        computed:{
            locationOptions(){
                let res =  this.changeChild(JSON.parse(JSON.stringify(this.options)))
                // console.log(res,'rrrrrrrrrrrrr',this.labelField,this.valueField)
                return res
            }
        },
        created(){
            // console.log(this.locationOptions,this.labelField,this.valueField,'options')
        },
        methods:{
            changeChild(list){
                list.forEach(item=>{
                    if(item[this.children] && item[this.children].length>0){
                        item[this.children] = this.changeChild(item[this.children])
                    }
                    item.label  = item[this.labelField]
                    item.value  = item[this.valueField]
                })
                return list
            }
        }
    }
})